package com.xlt.activiti.one;

import org.activiti.engine.ProcessEngine;
import org.activiti.engine.ProcessEngines;
import org.activiti.engine.TaskService;
import org.activiti.engine.task.Task;

import java.util.List;

public class ActivitiCompleteTask {


    public static void completeTask(String key, String roleName){
        // 1.得到processEngine对象
        ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine();
        // 2.得到TaskService
        TaskService taskService = processEngine.getTaskService();
        // 3.处理任务，结合当前用户任务列表查询操作，
        // 先查询
        List<Task> taskList = taskService.createTaskQuery()
                .processDefinitionKey(key)
                .taskAssignee(roleName)
                .list();
        // 在处理
        for (Task task:taskList){
            System.out.println("流程实例ID:"+task.getProcessInstanceId());
            System.out.println("任务ID:"+task.getId());
            System.out.println("任务负责人:"+task.getAssignee());
            System.out.println("任务名称:"+task.getName());
            taskService.complete(task.getId());
        }
    }
}
